<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="login.css">
</head>

<body>
    <div class="login">
        <form action="/login" method="post">
            <p>
                rememberMe :<br/>
                <select name="rememberMe" id="rememberMe">
                    <option value="1" selected="selected">保存1天</option>
                    <option value="7">保存7天</option>
                    <option value="30">保存一个月</option>
                    <option value="365">保存一年</option>
                    <option value="0">不保存</option>
                </select>
            </p>
            <p>
                username :<br/>
                <input type="text" name="username" id="username">
            </p>
            <p>
                password :<br/>
                <input type="password" name="password" id="password">
            </p>
            <p>
                <input type="submit" value="login" onclick="getInfo()" class="submit">
            </p>
        </form>
    </div>

    <script src="js/js.cookie.js"></script>
    <script src="js/jquery.js"></script>
    <script>
        //假如cookie已经有值了，即非等于未定义的时候，就将cookie的值付给输入框
        if (Cookies.get('username') != undefined) {
            document.getElementById('username').value = Cookies.get('username');
        }
        //假如cookie已经有值了，即非等于未定义的时候，就将cookie的值付给输入框
        if (Cookies.get('password') != undefined) {
            document.getElementById('password').value = Cookies.get('password');
        }
        //定义获取信息的函数
        function getInfo() {
            //获取用户输入的用户名的值
            var username = document.getElementById('username').value;
            //获取用户输入的密码的值
            var password = document.getElementById('password').value;
            //获取用户选择的时间
            let rememberMe = $("select option:selected").val();
            //将这个时间取整并转化为数值
            rememberMe = parseInt(rememberMe);
            console.log(rememberMe);
            //保存数据到cookie
            Cookies.set('username', username, { expires: rememberMe });
            Cookies.set('password', password, { expires: rememberMe });
            alert('hello');
        }
    </script>
</body>

</html>